package com.wang.sort;
//定义单链表
public class Demo9_ReverseList {
    public static class Node{
        public int value;
        public Node next;

        public Node(int data){
            value = data;
        }
    }
//定义双链表
    public static class DoubleNode{
        public int value;
        public DoubleNode last;
        public DoubleNode next;

        public DoubleNode(int data){
            value = data;
        }
    }
//单链表反转
    public static Node reverseLinkedList(Node head){
        Node pre = null;
        Node next = null;
        while (head != null){
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }
//双链表反转
    public static DoubleNode reverseDoubleList(DoubleNode head){
        DoubleNode pre = null;
        DoubleNode next = null;
        while (head != null){
            next = head.next;
            head.next = pre;
            head.next = next;
            pre = head;
            head = next;
        }
        return pre;
    }
}
